﻿@{
    ViewBag.Title = "Action Management";
    ViewBag.IsFormIndex = true;
}
@section FooterScript{
    <script type="text/javascript">
        $(function () {
            $.jqgrid.getCurr().jqGrid({
                    url: '@Url.Action("ActionList")',
                    datatype: "json",
                    mtype: 'post',
                    colNames: ['KeyGuid', '功能名', '控制器', '控制器区域', '更新时间', '是否删除', '操作'],
                    colModel: [
                        { name: 'KeyGuid', index: 'ActionGuid', width: 90, editable: false, hidden: true },
                        { name: '功能名', index: 'ActionName', width: 90, editable: true },
                        { name: '控制器', index: 'ControllerName', width: 90, editable: true },
                        { name: '控制器区域', index: 'AreaName', width: 90, editable: true },
                        { name: '更新时间', index: 'CommonColumns.LastModified', formatter: 'date',
                            formatoptions: { newformat: 'Y/m/d' }, width: 80, align: 'center', editable: true
                        },
                        { name: '是否删除', index: 'CommonColumns.IsDelete', width: 80, align: 'center',
                            editable: true, edittype: 'checkbox', editoptions: { value: '是:否' }
                        },
                        { name: 'Edit', index: 'Edit', width: 150, editable: false, align: 'center',
                            search: false, sortable: false
                        }
                    ],
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    pager: '#jqGridPager',
                    sortname: "CommonColumns.LastModified",
                    viewrecords: true,
                    hidegrid: false,
                    rownumbers: true,
                    sortorder: "desc",
                    caption: '@ViewBag.Title',
                    height: '100%',
                    width: '100%',
                    ondblClickRow: EditEntry
                });

            var iframeSize = $.bs.getContainerWidthAndHeight($.removePrefix($.sysRes.iframeName), false);
            $.jqgrid.getCurr().jqGrid('navGrid', '#jqGridPager', { add: false, edit: false, del: false })
                .navButtonAdd('#jqGridPager', {
                    caption: "编辑",
                    buttonicon: "ui-icon-add",
                    onClickButton: function () {
                        var id = $.jqgrid.getCurr().getGridParam("selrow");
                        if (id == null) {
                            alert("请选择行！");
                            return;
                        }
                        if (id == "newId") return;
                        $.jqgrid.getCurr().editRow(id);
                        $.jqgrid.getCurr().setCell(id, "Edit",
                    "<input id='Button1' type='button' value='提交' onclick='Update(\"" + id + "\")' /><input id='Button2' type='button' value='取消' onclick='Cancel(\"" + id + "\")' />");
                    }
                }).navButtonAdd('#jqGridPager', {
                    caption: "删除",
                    buttonicon: "ui-icon-del",
                    onClickButton: function () {
                        var id = $.jqgrid.getCurr().getGridParam("selrow");
                        if (id == null) {
                            alert("请选择行！");
                            return;
                        }
                        DeleteEntry(id);
                    }
                }).setGridWidth(iframeSize.width);

            $(".searchTable>tbody>tr>td:has(label)").addClass("evenTD");
        });

        //取消编辑状态
        function Cancel(id) {
            if (id == "newId")
                $.jqgrid.getCurr().delRowData("newId");
            else {
                $.jqgrid.getCurr().restoreRow(id);
                $.jqgrid.getCurr().setCell(id, "Edit", "&nbsp;");
            }
        }

        function EditEntry(id) {
            if (id == "newId")
                return;
            else {
                var keyGuid = $.jqgrid.getCurr().getCell(id, "KeyGuid");
                $.bs.showDialog({ url: '@Url.Action("Edit")?keyGuid=' + keyGuid, title: '修改功能描述' });
            }
        }

        function DeleteEntry(rowId) {
            if (rowId != 'newId') {
                var keyGuid = $.jqgrid.getCurr().getCell(rowId, 'KeyGuid');
                $.ajax({
                    url: '@Url.Action("Remove")',
                    type: 'post',
                    dataType: 'json',
                    data: { keyGuid: keyGuid },
                    success: function (result) {
                        if (result.ErrorCode == 0)
                            $.bs.showMsg('提示信息', result.ShowMsg);
                        else
                            $.bs.showErr('出错啦', result.ShowMsg);
                    }
                });
            }
            return;
        }
    </script>
}
<fieldset class="ui-corner-all">
    <legend>查询</legend>
    <table class="searchTable">
        <tr>
            <td><label>功能名称</label></td>
            <td>
                <input type="text" id="txtActionName" autofocus="true"
                 placeholder="功能名称" 
                 data-searchField="ActionName" data-searchOp="cn" />
            </td>
            <td rowspan="3">
                <input type="button" id="btnSearch" class="ui-button ui-jqgrid-search" value="查询" />
                @Html.ActionLink("新建功能", "Create", null, new { id = "lkCreate", @class = "ui-button ui-jqgrid-create" })
            </td>
        </tr>
        <tr>
            <td><label>控制器名称</label></td>
            <td>
                <input type="text" id="txtControllerName" placeholder="控制器名称" 
                 data-searchField="ControllerName" data-searchOp="cn" />
            </td>
        </tr>
        <tr>
            <td><label>控制器区域名称</label></td>
            <td>
                <input type="text" id="txtAreaName" placeholder="控制器名称" 
                 data-searchField="AreaName" data-searchOp="cn" />
            </td>
        </tr>
    </table>
</fieldset>
<table id="jqGridTable" class="ui-jqgrid-btable"></table>
<nav id="jqGridPager" class="ui-jqgrid-pager"></nav>
